/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ExpoManagement.java
 *
 * Created on Aug 11, 2010, 2:56:30 PM
 */
package Gui;

import BusinessLogic.ReorganizationExpo;
import DTO.Manager;
import DataAccess.DataUtility;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author Administrator
 */
public class pnExpo extends javax.swing.JPanel {

    private Manager manager;
    private ReorganizationExpo reoExpo;
    private JLabel lblName;

    /** Creates new form ExpoManagement */
    public pnExpo(Manager manager, JLabel lblName) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        this.lblName = lblName;
        this.manager = manager;
        //initial Reorganization
        reoExpo = new ReorganizationExpo();

        initComponents();
        add(pnSource);
        pnSource.setBounds(50, 50, 500, 150);
        pnReorganization.setBounds(50, 220, 500, 200);
        lbSource.setBounds(20, 20, 100, 50);
        buttonDetail.setBounds(360, 115, 120, 30);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        pnSource = new javax.swing.JPanel();
        lbSource = new javax.swing.JLabel();
        buttonDetail = new javax.swing.JLabel();
        pnReorganization = new javax.swing.JPanel();
        lbNamExpo = new javax.swing.JLabel();
        txtExpo = new javax.swing.JTextField();
        lbNotes = new javax.swing.JLabel();
        btnYes = new javax.swing.JButton();
        btnNo = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));

        pnSource.setBackground(new java.awt.Color(255, 255, 255));
        pnSource.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Zone Management", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N

        lbSource.setText("<html>\n<b>Function: </b><br>\n  Display all information of Zones<br>\n  Create a new  Zone and  update information of Zone then save it into Zone table in database.<br><br>\n<b>Notes: </b><br>\nIn a Zone contain many same Booths, You should be specify size, fees and number Booth when create a Zone.<br>\n</html>");

        buttonDetail.setBackground(new java.awt.Color(255, 255, 255));
        buttonDetail.setFont(new java.awt.Font("Tahoma", 1, 11));
        buttonDetail.setForeground(new java.awt.Color(0, 70, 213));
        buttonDetail.setText("<html> <u>Detail Source</u> </html>");
        buttonDetail.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                buttonDetailMousePressed(evt);
            }
        });

        javax.swing.GroupLayout pnSourceLayout = new javax.swing.GroupLayout(pnSource);
        pnSource.setLayout(pnSourceLayout);
        pnSourceLayout.setHorizontalGroup(
            pnSourceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnSourceLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(lbSource, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 12, Short.MAX_VALUE)
                .addComponent(buttonDetail, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        pnSourceLayout.setVerticalGroup(
            pnSourceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnSourceLayout.createSequentialGroup()
                .addComponent(lbSource, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
            .addGroup(pnSourceLayout.createSequentialGroup()
                .addContainerGap(126, Short.MAX_VALUE)
                .addComponent(buttonDetail, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pnReorganization.setBackground(new java.awt.Color(255, 255, 255));
        pnReorganization.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Reorganization New Expo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 12))); // NOI18N
        pnReorganization.setLayout(null);

        lbNamExpo.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbNamExpo.setText("Name Expo");
        pnReorganization.add(lbNamExpo);
        lbNamExpo.setBounds(40, 30, 70, 14);

        txtExpo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtExpoActionPerformed(evt);
            }
        });
        pnReorganization.add(txtExpo);
        txtExpo.setBounds(130, 30, 300, 20);

        lbNotes.setText("<html>\n<b>Notes:</b><br>\n\t- With admin account.You can use this functionl to reorganiza new Expo. When you reorganiza new Expo, all Exhibitor account in database will be reset status is NOT JOIN and ImportantDate of will be invisible, a new ImportantDate will refer to Exhibitor.<br><br>\n\n\t- If you want to do this, You need input correct Name Expo.<br>\n\tChoose Yes to execute function.<br>\n\n</html>\n");
        pnReorganization.add(lbNotes);
        lbNotes.setBounds(40, 60, 470, 100);

        btnYes.setText("Yes");
        btnYes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnYesActionPerformed(evt);
            }
        });
        pnReorganization.add(btnYes);
        btnYes.setBounds(140, 180, 70, 23);

        btnNo.setText("No");
        pnReorganization.add(btnNo);
        btnNo.setBounds(220, 180, 70, 23);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(17, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnReorganization, javax.swing.GroupLayout.PREFERRED_SIZE, 560, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(pnSource, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(pnSource, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnReorganization, javax.swing.GroupLayout.PREFERRED_SIZE, 213, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(16, Short.MAX_VALUE))
        );

        getAccessibleContext().setAccessibleParent(this);
    }// </editor-fold>//GEN-END:initComponents

    private void buttonDetailMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buttonDetailMousePressed
        // TODO add your handling code here:
        DLZone dialog = new DLZone(new javax.swing.JFrame(), true);
        dialog.setVisible(true);

    }//GEN-LAST:event_buttonDetailMousePressed

    private void txtExpoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtExpoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtExpoActionPerformed

    private void btnYesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnYesActionPerformed
        // TODO add your handling code here:
        if (manager.getPower() != 1) {
            JOptionPane.showMessageDialog(this, "You have not power!!", "Warning", JOptionPane.WARNING_MESSAGE);
        } else if (manager.getPower() == 1) {
            if (txtExpo.getText().equals("")) {
                JOptionPane.showMessageDialog(pnSource, "Name of Expo is empty!!!");
                return;
            }
            int a = JOptionPane.showConfirmDialog(this, "Are you sure do this?", "Warning", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
            if (a == JOptionPane.YES_OPTION) {
                String nameOfExpo = txtExpo.getText();
                //settext for nameOfExpo
                lblName.setText(nameOfExpo);
                //call method reset
                reoExpo.reorganization(nameOfExpo);
            }
        }
    }//GEN-LAST:event_btnYesActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnNo;
    private javax.swing.JButton btnYes;
    private javax.swing.JLabel buttonDetail;
    private javax.swing.JLabel lbNamExpo;
    private javax.swing.JLabel lbNotes;
    private javax.swing.JLabel lbSource;
    private javax.swing.JPanel pnReorganization;
    private javax.swing.JPanel pnSource;
    private javax.swing.JTextField txtExpo;
    // End of variables declaration//GEN-END:variables
}
